extends RefCounted
class_name BuffFactory

## 创建攻击力提升buff
static func create_attack_buff(damage_bonus: float, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("攻击提升")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(0.0)
	buff.add_now_modifier("additional_damage", damage_bonus)
	return buff

## 创建移动速度提升buff
static func create_speed_buff(speed_bonus: float, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("移动速度提升")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(0.0)
	buff.add_now_modifier("move_speed", speed_bonus)
	return buff

## 创建生命值恢复buff
static func create_heal_buff(heal_amount: float, tick_interval: float = 1.0, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("生命恢复")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(tick_interval)
	buff.add_tick_modifier("current_hp", heal_amount)
	return buff


## 创建生命值恢复buff百分比（暂时不可叠加）
static func create_heal_buff_percent(heal_percent: float, tick_interval: float = 1.0, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("百分比生命恢复")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(tick_interval)
	buff.add_tick_modifier("heal_percent", heal_percent / 100)
	return buff

## 创建魔法值恢复buff（暂时不可叠加）
static func create_mana_buff_percent(mana_percent: float, tick_interval: float = 1.0, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("百分比魔法恢复")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(tick_interval)
	buff.add_tick_modifier("mana_percent", mana_percent / 100)
	return buff

## 创建护盾buff
static func create_shield_buff(shield_amount: float, duration: float = 10.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("护盾")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(0.0)
	buff.add_now_modifier("shield", shield_amount)
	return buff

## 创建添加攻速buff
static func create_attack_speed_buff(attack_speed: float, duration: float = 10.0) -> BuffData:
	return create_custom_buff(
		"攻速加快", duration, 1, 0.0, "attack_speed", attack_speed
	)

## 创建添加攻速百分比buff
static func create_attack_speed_buff_percent(buff_name: String, attack_speed_percent: float, duration: float = 10.0) -> BuffData:
	return create_custom_buff_percent(
		buff_name, duration, 1, 5.0, "additional_attack_speed", attack_speed_percent, "attack_speed"
	)
 
## 创建自定义buff
static func create_custom_buff_percent(
	name: String, 
	duration: float, 
	max_stacks: int = 1, 
	tick_interval: float = 0.0,
	modifier_name: String = "", 
	percent_value: float = 0.0,
	## 获取原来的名称
	origin_name: String = ""
	) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	var origin_value = Utils.get_player_stats_value(origin_name)
	var value = origin_value * percent_value
	buff.set_buff_name(name)
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(tick_interval)
	if not modifier_name.is_empty():
		buff.add_now_modifier(modifier_name, value)
	return buff

## 创建自定义buff
static func create_custom_buff(name: String, duration: float, max_stacks: int = 1, tick_interval: float = 0.0, modifier_name: String = "", value: float = 0.0) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name(name)
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(tick_interval)
	if not modifier_name.is_empty():
		buff.add_now_modifier(modifier_name, value)
	return buff

## 创建中毒效果buff
static func create_poison_buff(damage_per_tick: float, duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("中毒")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	return buff

## 创建烧伤效果buff
static func create_burn_buff(damage_per_tick: float, duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("烧伤")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	return buff

## 创建冰冻效果buff
static func create_freeze_buff(duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("冰冻")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(0.0)  # 无持续伤害
	buff.add_now_modifier("move_speed", -100)  # 减速效果
	return buff

## 创建格挡效果buff
static func create_block_buff(duration: float) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("格挡")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(0.0)  # 无持续伤害
	return buff

## 创建眩晕效果buff
static func create_stun_buff(duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("眩晕")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(0.0)  # 无持续伤害
	buff.add_now_modifier("move_speed", -200)  # 完全停止移动
	return buff

## 创建流血效果buff
static func create_bleed_buff(damage_per_tick: float, duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("流血")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	return buff

## 创建电击效果buff
static func create_shock_buff(damage_per_tick: float, duration: float, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("电击")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	return buff

## 创建灼烧效果buff（用于敌人）
static func create_enemy_burn_buff(damage_per_tick: float, duration: float = 3.0, max_stacks: int = 5) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("灼烧")
	buff.set_duration(duration)
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	return buff

## 创建燃烧吧效果buff（用于玩家）
static func create_burning_buff(damage_per_tick: float, attack_speed_bonus: float, duration: float = -1.0, max_stacks: int = 1) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("燃烧")
	buff.set_duration(duration)  # -1表示永久持续
	buff.set_max_stacks(max_stacks)
	buff.set_tick_interval(1.0)  # 每秒造成一次伤害
	buff.add_tick_modifier("current_hp", -damage_per_tick)
	buff.add_now_modifier("additional_attack_speed", attack_speed_bonus)
	return buff 

## 创建隐身效果buff
static func create_stealth_buff(duration: float) -> BuffData:
	var buff = Pandora.get_entity(PandoraCategories.BUFF).instantiate() as BuffData
	buff.set_buff_name("隐身")
	buff.set_duration(duration)
	buff.set_max_stacks(1)
	buff.set_tick_interval(0.0)  # 无持续效果
	return buff 
